package com.chenjl.generator.generated.impl;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;
import org.mybatis.generator.api.dom.xml.Attribute;
import org.mybatis.generator.api.dom.xml.TextElement;
import org.mybatis.generator.api.dom.xml.XmlElement;

import com.chenjl.generator.Generator;
import com.chenjl.generator.generated.AbstractGenerated;
/**
 * 单个逻辑删除
 * 2020-4-8 17:04:57
 * @author chenjinlong
 */
public class LogicDeleteByPrimaryKeyGenerated implements AbstractGenerated {
	
	
	@Override
	public Method clientGenerated(String baseRecordType) {
		//单个逻辑删除,logicDeleteByPrimaryKey
		Method logicDeleteByPrimaryKeyMethod = new Method();
		logicDeleteByPrimaryKeyMethod.addJavaDocLine("/**");
		logicDeleteByPrimaryKeyMethod.addJavaDocLine(" * 单个逻辑删除,set is_deleted=1返回影响行数");
		logicDeleteByPrimaryKeyMethod.addJavaDocLine(" */");
		logicDeleteByPrimaryKeyMethod.setName("logicDeleteByPrimaryKey");
		logicDeleteByPrimaryKeyMethod.setVisibility(JavaVisibility.PUBLIC);
		logicDeleteByPrimaryKeyMethod.setReturnType(new FullyQualifiedJavaType("java.lang.Integer"));
		logicDeleteByPrimaryKeyMethod.addParameter(new Parameter(new FullyQualifiedJavaType("Long"),"pkId"));
		
		return logicDeleteByPrimaryKeyMethod;
	}
	
	@Override
	public XmlElement sqlMapDocumentGenerated(IntrospectedTable introspectedTable,String tableName) {
		XmlElement logicDeleteByPrimaryKeyXmlElement = new XmlElement("update");
		logicDeleteByPrimaryKeyXmlElement.addAttribute(new Attribute("id", "logicDeleteByPrimaryKey"));
		logicDeleteByPrimaryKeyXmlElement.addAttribute(new Attribute("parameterType","java.lang.Long"));
		logicDeleteByPrimaryKeyXmlElement.addElement(new TextElement("update "+ tableName + " set "+Generator.LOGIC_DELETE_COLUMN_NAME+" = 1 where id = #{pkId,jdbcType=BIGINT}"));
		logicDeleteByPrimaryKeyXmlElement.addElement(new TextElement(" and "+Generator.LOGIC_DELETE_COLUMN_NAME+" = 0"));
		
		return logicDeleteByPrimaryKeyXmlElement;
	}
	
}